package com.zengzhuo.mutithread.basic.create;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * TODO
 *
 * @author zhuo.zeng
 * @version 1.0
 * @date 2021/9/24 8:39
 */
public class CreateDemo {
    private static Logger logger = LoggerFactory.getLogger(CreateDemo.class);
    public static final int MAX_TURN = 5;

    public static String getCurThreadName() {
        return Thread.currentThread().getName();
    }

    //线程的编号
    static int threadNo = 1;

    static class DemoThread extends Thread {
        public DemoThread() {
            super("DemoThread-" + threadNo++);
        }

        @Override
        public void run() {
            for (int i = 1; i < MAX_TURN; i++) {
                logger.info(getName() + ", 轮次：" + i);
            }
            logger.info(getName() + " 运行结束.");
        }
    }

    public static void main(String[] args) {
        Thread thread = null;
        //方法一：使用Thread子类创建和启动线程
        for (int i = 0; i < 2; i++) {
            thread = new DemoThread();
            thread.start();
        }
        logger.info(getCurThreadName() + " 运行结束.");
    }
}
